import request from './index'

// export const getUsers = () => request.get("/user/test?pageNum=1&pageSize=10&search=")
//登录
export const login = (params: LoginAPIRes): Promise<LoginAPIReq> => request.post("/user/login", params)
//预定添加
export const addBooking = (params: BookingRes): Promise<Success> => request.post("/booking/add", params)
//获取预定数据
export const getBookData = (params: PageRes): Promise<PageReq> => request.get("/booking/data", { params })
//获取全部房间信息
export const getRoomData = (): Promise<NoPageReq> => request.get("/room/data")
//客户入住添加信息
export const addCustomer = (params: RoomRes): Promise<NoPageReq> => request.post("/customer/add", params)
//获取客户信息
export const getCustomerData = (params: PageRes): Promise<PageReq> => request.get("/customer/data", { params })
//用户续住
export const customerRenew = (params: CustomerType): Promise<Success> => request.put("/customer/renew", params)
//退房
export const customerCheckOut = (params: checkOutRes): Promise<Success> => request.post("/bill/checkOut", params)
//账单信息
export const getBillData = (params: PageRes): Promise<PageReq> => request.get("/bill/data", { params })
//已打扫房间
export const roomcleanUp = (roomId: string): Promise<Success> => request.put("/room/cleanUp?roomId=" + roomId)


//返回当前时间
export const getCurrentDate = (times: string[]) => {
  let time = times[1]
  let mdy: any = times[0]
  mdy = mdy.split('/')
  let month = parseInt(mdy[0]);
  let day = parseInt(mdy[1]);
  let year = parseInt(mdy[2])
  return year + '-' + month + '-' + day + ' ' + time
}

// 两个时间相减，返回天数
export const DateDiff = (d1: any, d2: any) => {
  var day = 24 * 60 * 60 * 1000;
  try {
    var dateArr = d1.split("-");
    var checkDate = new Date();
    checkDate.setFullYear(dateArr[0], dateArr[1] - 1, dateArr[2]);
    var checkTime = checkDate.getTime();

    var dateArr2 = d2.split("-");
    var checkDate2 = new Date();
    checkDate2.setFullYear(dateArr2[0], dateArr2[1] - 1, dateArr2[2]);
    var checkTime2 = checkDate2.getTime();

    var cha:number = (checkTime - checkTime2) / day;
    return cha;
  } catch (e) {
    return 0;
  }
}

